"""
@author: Sergiy Tsymbalyuk
"""

import logging

from pylons import url, tmpl_context as c
from pylons.i18n import lazy_ugettext as _

from repoze.what.plugins.pylonshq import ControllerProtector
from repoze.what.predicates import has_permission

from hrms.lib.base import Session, render, BaseController
from hrms.model.education import Education, School, Specialty

log = logging.getLogger(__name__)

@ControllerProtector(has_permission('hrms.administer.education'))
class SchoolController(BaseController):
    def view(self, id):
        c.school = Session.query(School).get(id)
        return render('/hrms/education/school.html')

    def graduates(self, id):
        c.school = Session.query(School).get(id)
        c.graduates = Session.query(Education).join(Specialty) \
            .filter(Specialty.school_id == id) \
            .order_by(Education.graduated).all()
        return render('/hrms/education/graduates.html')
        